package com.google.code.alpaca.example.server.handler;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.google.code.alpaca.example.rpc.MessageSaveAction;
import com.google.code.alpaca.example.rpc.VoidResult;
import com.google.code.alpaca.example.server.MessageRepository;

public class MessageSaveHandler implements ActionHandler<MessageSaveAction, VoidResult>{

  private MessageRepository messageRepository = new MessageRepository();

  @Override
  public Class<MessageSaveAction> getActionType() {
    return MessageSaveAction.class;
  }

  @Override
  public VoidResult execute(MessageSaveAction action, ExecutionContext context)
      throws DispatchException {
    messageRepository.create(action.getMessage());
    return VoidResult.VOID;
  }

  @Override
  public void rollback(MessageSaveAction action, VoidResult result,
      ExecutionContext context) throws DispatchException {
  }

}
